package alingrad.engine.src.graphics;

import org.lwjgl.opengl.GL11;

import alingrad.engine.src.collisions.CollisionMaskData;

/**
 * A texture class that can be drawn.
 * @author alingrad
 *
 */
public class Texture {
	/**
	 * The type of texture.
	 */
	private int target;

	/**
	 * The id of the texture.
	 */
	private int textureID;

	/**
	 * The width of the image.
	 */
	private int width;

	/**
	 * The height of the image.
	 */
	private int height;

	/**
	 * The width of the texture.
	 */
	private int textureWidth;

	/**
	 * The height of the texture.
	 */
	private int textureHeight;

	/**
	 * The ratio of the image width over the texture width.
	 */
	private float widthRatio;

	/**
	 * The ratio of the image height over teh texture height.
	 */
	private float heightRatio;

	/**
	 * The collision mask of the texture.
	 */
	private CollisionMaskData data;

	/**
	 * Constructs a texture with a target and id.
	 * @param target the target.
	 * @param textureID the texture id.
	 */
	public Texture(int target, int textureID) {
		this.target = target;
		this.textureID = textureID;
	}

	/**
	 * Binds the texture.
	 */
	public void bind() {
		GL11.glBindTexture(target, textureID);
	}

	/**
	 * Sets the image height.
	 * @param height height to set.
	 */
	public void setHeight(int height) {
		this.height = height;
		setHeight();
	}

	/**
	 * Sets the image width.
	 * @param width width to set.
	 */
	public void setWidth(int width) {
		this.width = width;
		setWidth();
	}

	/**
	 * Sets the texture height.
	 * @param height height to set.
	 */
	public void setTextureHeight(int height) {
		textureHeight = height;
		setHeight();
	}

	/**
	 * Sets the texture width.
	 * @param width width to set.
	 */
	public void setTextureWidth(int width) {
		textureWidth = width;
		setWidth();
	}

	/**
	 * Gets the image height.
	 * @return the image height.
	 */
	public int getImageHeight() {
		return height;
	}

	/**
	 * Gets the image width.
	 * @return the image width.
	 */
	public int getImageWidth() {
		return width;
	}

	/**
	 * Gets the height ratio.
	 * @return the height ratio.
	 */
	public float getHeight() {
		return heightRatio;
	}

	/**
	 * Gets the width ratio.
	 * @return the width ratio.
	 */
	public float getWidth() {
		return widthRatio;
	}

	/**
	 * Resets the height ratio.
	 */
	public void setHeight() {
		if (textureHeight != 0)
			heightRatio = ((float)height) / textureHeight;
	}

	/**
	 * Resets the width ratio.
	 */
	public void setWidth() {
		if (textureWidth != 0)
			widthRatio = ((float)width) / textureWidth;
	}

	/**
	 * Gets the collision mask of the texture.
	 * @return the collision mask.
	 */
	public CollisionMaskData getCollisionMaskData() {
		return data;
	}

	/**
	 * Sets the collision mask of the texture.
	 * @param mask the collision mask.
	 */
	public void setData(CollisionMaskData data) {
		this.data = data;
	}
}